﻿using System;

namespace HCore
{
    public static class Debug
    {
        public static void Assert(bool result, string errorMsg = "")
        {
            if (!result)
            {
                throw new Exception(errorMsg);
            }
        }

        public static void PrintRtt(string prefix, InputMemoryBitStream input)

        {
            //Logger.Log(prefix + "[" + DateTime.Now.ToString("hh:mm:ss fff") + "] PrintRtt");
            int start = 0;
            int len = input.GetByteLength();
            while (start < len)
            {
                input.SetBitHead((start + 20) * 8);
                int l = input.ReadInt();
                if (l > 0)
                {
                    byte packetType = input.ReadByte();
                    if (packetType == PacketType.RTT)
                    {
                        input.ReadInt();
                        int frameCount = input.ReadInt();
                        Logger.Log(prefix + "[" + DateTime.Now.ToString("hh:mm:ss fff") + "] frameCount: " + frameCount);
                    }
                }
                
                
                start += 24 + l;

            }
            
            input.SetBitHead(0);
        }
    }
}